<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <base href="<%=basePath%>">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <%@ include file="../common/baseCss.jsp" %>
    <title>多站点管理</title>
</head>
<body>

<div class="page-container">
    <div class="button-group">
        <a href="javascript:;" onclick="layer_show('添加站点','multiSiteAddPage','','')" class="btn btn-primary radius">
            <i class="iconfont marginRight6">&#xe600;</i>添加站点
        </a>
        <a class="btn btn-success radius r" href="javascript:location.replace(location.href);" title="刷新">
            <i class="iconfont">&#xe618;</i>
        </a>
    </div>
    <table class="table table-border table-bordered table-hover table-bg mytable">
        <thead>
        <tr class="text-c tableTH">
            <th width="100">ID</th>
            <th width="100">站点名</th>
            <th width="100">创建时间</th>
            <th width="100">操作</th>
        </tr>
        </thead>
        <tbody id=sitemodule class='tableTR'>
        </tbody>
    </table>
    <div class='pageNo'>
		<span class="r">共
			<span id="dataNum"></span> 条数据
		</span>
        <center id="page" class='myPage'></center>
    </div>
</div>


<%@ include file="../common/baseJs.jsp" %>
<script type="text/javascript" src="manager/js/plugin/jquery.dataTables.min.js"></script>
<script type="text/javascript">
    var rootPath = getRootPath();
    $(function () {
        $.ajax({
            url: rootPath + '/listAllSite',
            type: 'POST',
            contentType: 'application/json',
            dataType: 'json',
            success: function (data) {
                console.log(data)
                site_show(data.returnObject);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                layer.alert("error:(");
            }
        });
    });

    function site_show(data) {
        var length = data.length;
        var tr;
        for (var i = 0; i < length; i++) {
            tr += "<tr class='text-c' id='site_" + data[i].id + "' name='siteTr'>";
            tr += "<td>" + data[i].id + "</td>";
            tr += "<td>" + data[i].siteName + "</td>";
            tr += "<td>" + data[i].cts + "</td>";
            tr += "<td>"
            tr += "<a title='编辑' href='javascript:;' onclick='layer_show(\"修改站点名称\",\"multiSiteEditPage?id=" + data[i].id + "\", \"\",\"\")' style='text-decoration:none'><i class='iconfont marginLeft12'>&#xe60a;</i></a>";
            tr += "<a title='域名管理' href='javascript:;' onclick='layer_show(\"站点域名管理\",\"siteDomainPage?siteId="+ data[i].id + "\", \"\",\"\")' style='text-decoration:none'><i class='iconfont marginLeft12'>&#xe60f;</i></a>";
            tr += "<a title='信息管理' href='javascript:;' onclick='layer_show(\"站点信息管理\",\"siteInfoPage?siteId="+ data[i].id + "\", \"\",\"\")' style='text-decoration:none'><i class='iconfont marginLeft12'>&#xe60f;</i></a>";
            tr += "<a title='删除' href='javascript:;' onclick='site_del(this," + "\"" + data[i].id + "\")' class='ml-5' style='text-decoration:none'><i class='iconfont marginLeft12'>&#xe612;</i></a>" + "</td></tr>";
        }
        $("#sitemodule").empty();
        $("#sitemodule").append(tr);
    }

    function site_del(data, id) {
        layer.confirm('删除须谨慎，确认要删除吗？',function(index){
            $.ajax({
                url: rootPath + '/delSite',
                type: 'POST',
                data: {
                    'id': id
                },
                success: function (data) {
                    layer.msg('成功', {icon: 1, time: 1000}, function () {
                        window.location.href = rootPath + '/multiSitePage';
                    });
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    layer.alert("error:(");
                }
            });
        });
    }
</script>


</body>
</html>
